package com.yanxu.threadandobjectmethods.join;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2025/3/24-2025
 * @Description: 这里用一句话描述这个类的作用
 */
public class JoinDemo {
    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(new Runnable() {
            public void run() {
                System.out.println(Thread.currentThread().getName() +" start!");
                try {
                    Thread.sleep(5000);
                    System.out.println(Thread.currentThread().getName()+" end!");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "子线程");

        thread1.start();
        //子线程加入我们， 因此是【主线程】等待 子线程执行完毕。
        thread1.join();
        System.out.println("主线程执行完毕!!!");
    }
}